package org.streets.eis.entity;

import java.io.Serializable;
import java.sql.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.streets.database.annotations.NestedFetch;


@Entity
@Table(name="EIS_POSITION")
public class Position  implements Serializable {
	private static final long serialVersionUID = 1L;
	
	@Id
	private String id;
	@Column
	private String name;
	@Column
	private Date validTo;
	@Column
	private String organId;

	@NestedFetch(
		type=Role.class,
		value="select * from eis_roles where id in (select role_id from EIS_POS_ROLE_MAP where status = 1 and trim(pos_id) = :id)"
	)
	private List<Role> roles; 
	
	public Position() {
		
	}
	
	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public Date getValidTo() {
		return validTo;
	}
	
	public void setValidTo(Date validTo) {
		this.validTo = validTo;
	}
	
	public String getOrganId() {
		return organId;
	}

	public void setOrganId(String organId) {
		this.organId = organId;
	}	
	
	@Override
	public int hashCode(){
		return id.hashCode();
	}
	
	@Override
	public boolean equals(Object obj){
		return obj!=null&&(obj instanceof Position)&&id.equals(((Position)obj).id);
	}	
}
